//
//  NoteDao.m
//  极致荟
//
//  Created by hetao on 14-8-8.
//  Copyright (c) 2014年 mac. All rights reserved.
//

#import "NoteDao.h"

@implementation NoteDao

///添加聊天记录
+ (void)insertData:(Note *)note
{
    FMDatabase *db=[VXSqli shareVxsqlit].db;
    int i=note.noteType;
    if([db executeUpdate:@"insert into note(senderId,recipientId,conte,type,notedate,vodeLeng) values(?,?,?,?,?,?)",[NSNumber numberWithInt:note.senderId],[NSNumber numberWithInt:note.recipientId],note.content,[NSNumber numberWithInt:i],[NSNumber numberWithLongLong:note.noteDate.timeIntervalSince1970],note.vodeleng])
    {
        NSLog(@"成功");
    }else
    {
        NSLog(@"失败");
    }
    
}

///查询好友聊天记录
+ (NSArray *)selectData:(int)ouserid
{
    FMDatabase *db=[VXSqli shareVxsqlit].db;
    FMResultSet *set=[db executeQuery:@"select * from note where senderId=? or recipientId=?",[NSNumber numberWithInt:ouserid],[NSNumber numberWithInt:ouserid]];
    NSMutableArray *arr=[[NSMutableArray alloc]init];
    while (set.next)
    {
      
        Note *snote=[[Note alloc]init];
        snote.noteId=[set intForColumn:@"id"];
        snote.senderId=[set intForColumn:@"senderId"];
        snote.recipientId=[set intForColumn:@"recipientId"];
        snote.content=[set stringForColumn:@"conte"];
        snote.noteType=[set intForColumn:@"type"];
        snote.noteDate=[NSDate dateWithTimeIntervalSince1970:[set longLongIntForColumn:@"notedate"]];
        snote.vodeleng=[set stringForColumn:@"vodeLeng"];
        if(snote.senderId==[User defuceUser].userId || snote.recipientId==[User defuceUser].userId)
        {
          [arr addObject:snote];
        }
        
    }
    [set close];
    return arr;
}
@end
